<template lang="html">
  <div>
    <div class="search">
        <div class="input">
             <p><label>订单编号：</label><el-input placeholder="请输入内容" v-model="pageData.name"></el-input></p>
             <p><label>手机号：</label><el-input placeholder="请输入内容" v-model="pageData.phone"></el-input></p>
             <p><label>用户退货：</label>
                 <el-select v-model="pageData.orderStatus" placeholder="请选择" @change="getType">
                     <el-option value="">请选择</el-option>
                    <el-option
                      v-for="item in usersales"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-select>
             </p>
             <p><label>订单类型：</label>
               <el-select v-model="pageData.consignType" placeholder="请选择" @change="getType">
                   <el-option value="">请选择</el-option>
                  <el-option
                    v-for="item in type"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
             </el-input></p>

             <p><el-button type="primary" class="se" style="margin-left:10px;" @click="search">搜索</el-button></p>
        </div>
    </div>
    <tableVue :list="list" :state="false" v-loading="pageData.loading" :total="total" @sizeChange="handSize">
        <slot>
          <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  @click="details(scope.row)">详情
                </el-button>
                <el-button
                  size="mini"
                  type="success"
                  v-if="scope.row.orderStatus == '用户不同意'"
                  @click="sales(scope.row)">退货
                </el-button>
              </template>
          </el-table-column>
        </slot>
    </tableVue>
    <dialogVue title="操作" :dialog="dialog" @close="changeData" :state="false" >
        <slot>
            <el-form :model="ruleForm" ref="ruleForm" label-width="120px" class="demo-ruleForm">
                  <el-form-item label="物流单号" prop="logisticsNo">
                      <el-input v-model="ruleForm.logisticsNo" placeholder="请输入内容"></el-input>
                      <el-button type="primary"  :loading="Vloading" @click="getlogistId">查询快递公司</el-button>
                   </el-form-item>
                   <el-form-item label="姓名" prop="logisticsNo">
                       <el-input v-model="contactName" placeholder="请输入内容" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="联系方式" prop="logisticsNo">
                        <el-input v-model="contactTel" placeholder="请输入内容" disabled></el-input>
                     </el-form-item>
                   <el-form-item label="快递公司" prop="logisticsNo">
                       <el-select filterable v-model="ruleForm.logisticsCompanyCode" placeholder="请选择" :disabled="disableda">
                           <el-option value="">请选择</el-option>
                           <el-option
                             v-for="(item,key) in logistics"
                             :key="key"
                             :label="item.companyName"
                             :value="item.companyCode">
                           </el-option>
                         </el-select>
                    </el-form-item>
                   <el-form-item class="confirm">
                       <el-button type="primary"  @click="upForm('post')">确定</el-button>
                   </el-form-item>
            </el-form>
        </slot>
    </dialogVue>
  </div>
</template>

<script>
  import dialogVue from '@/components/dialog.vue'
  import Data from './consignIndentData.js'
  import tableVue from '@/components/alltable.vue'
  import {
    consignIndentList,
    usersales,
    getLogisticsInfo
  } from "@/api/product/consignIndent";
  export default {
    components : {
      tableVue,
      dialogVue
    },
    data () {
       return JSON.parse(JSON.stringify(Data))
    },
    mounted () {
      this.getconsignIndentList();
    },
    methods : {
      upForm () {
        this.$confirm('此操作将发货物品, 是否继续?', '提示', {
           confirmButtonText: '确定',
           cancelButtonText: '取消',
           type: 'warning'
         }).then(() => {
           usersales(this.orderId,this.ruleForm.logisticsCompanyCode,this.ruleForm.logisticsNo,'uid' + String(this.orderId)).then(res=>{
             if (res.data.code == 'OK') {
               this.$message.success('发货成功')
               var data = {
                 contactTel : this.pageData.phone,
                 consignType : this.pageData.consignType,
                 orderStatus : this.pageData.orderStatus,
                 orderNo : this.pageData.name,
                 orderStatus : this.pageData.orderStatus
               }
               this.getconsignIndentList(data)
                 this.dialog = false;
             } else {
               this.$message.error(res.data.message)
             }
           })
         }).catch(() => {
           this.$message({
             type: 'info',
             message: '已取消发货'
           });
         });
      },
      getlogistId () {//获取物流信息
         if (this.ruleForm.logisticsNo) {
           this.Vloading = true;
           getLogisticsInfo(this.ruleForm.logisticsNo).then(res=>{
              if (res.data.code == 'OK') {
                  this.logistics = res.data.data;
                   this.disableda = false;
                   this.Vloading = false;
              } else {
                this.$message.error(res.data.message)
                this.Vloading = false;
              }
           })
         } else {
           this.$message.error('请输入快递单号!!')
            this.disableda = true;
         }
      },
      changeData (data) {
        this.dialog = data;
      },
      sales (item) {
        this.contactName = item.contactName;
        this.contactTel = item.contactTel;
        this.orderId = item.orderId;
        this.dialog = true;
      },
      getconsignIndentList (data) {
        this.pageData.loading = true;
        consignIndentList (data).then(res=>{
          if (res.data.code == 'OK') {
            this.pageData.loading = false;
            this.total = res.data.data.total;
            this.list.tbody = res.data.data.records.map(item=>{
              if (item.consignType == 'MEN_DIAN') {
                  item.consignType = '去门店'
                  switch (item.orderStatus) {
                    case 0 : item.orderStatus = '等待用户到店'
                      break;
                    case 1 : item.orderStatus = '用户到店'
                      break
                    case 4 : item.orderStatus = '订单完成（待打款）'
                      break
                    case 5 : item.orderStatus = '打款完成（可赎回）'
                      break
                    case 9 : item.orderStatus = '已取消'
                      break
                    case 10 : item.orderStatus = '待出库'
                      break
                    case 11 : item.orderStatus = '已出库'
                      break
                    case 12 : item.orderStatus = '待收货'
                      break
                    case 13 : item.orderStatus = '已赎回'
                      break
                    case 14 : item.orderStatus = '到期不可赎回'
                      break
                    default:
                  }
              } else if (item.consignType == 'SHANG_MEN') {
                  item.consignType = '上门'
                  switch (item.orderStatus) {
                    case 0 : item.orderStatus = '等待评估师上门'
                      break;
                    case 1 : item.orderStatus = '评估师已上门'
                      break
                    case 4 : item.orderStatus = '订单完成（待打款）'
                      break
                    case 5 : item.orderStatus = '打款完成（可赎回）'
                      break
                    case 9 : item.orderStatus = '已取消'
                      break
                    case 10 : item.orderStatus = '待出库'
                      break
                    case 11 : item.orderStatus = '已出库'
                      break
                    case 12 : item.orderStatus = '待收货'
                      break
                    case 13 : item.orderStatus = '已赎回'
                      break
                    case 14 : item.orderStatus = '到期不可赎回'
                      break
                    default:
                  }
              } else if (item.consignType == 'KUAIDI') {
                item.consignType = '快递'
                switch (item.orderStatus) {
                  case 0 : item.orderStatus = '待收货'
                    break;
                  case 1 : item.orderStatus = '已收货'
                    break
                  case 2 : item.orderStatus = '待估价'
                    break
                  case 3 : item.orderStatus = '已估价（用户可取消）'
                    break
                  case 4 : item.orderStatus = '订单完成（待打款）'
                    break
                  case 5 : item.orderStatus = '打款完成（可赎回）'
                    break
                  case 6 : item.orderStatus = '用户不同意'
                    break
                  case 7 : item.orderStatus = '待收货（用户不同意时）'
                    break
                  case 8 : item.orderStatus = '已完成（用户不同意时）'
                    break
                  case 9 : item.orderStatus = '已取消'
                    break
                  case 10 : item.orderStatus = '待出库'
                    break
                  case 11 : item.orderStatus = '已出库'
                    break
                  case 12 : item.orderStatus = '待收货'
                    break
                  case 13 : item.orderStatus = '已赎回'
                    break
                  case 14 : item.orderStatus = '到期不可赎回'
                    break
                  default:
                }
              } else {
                item.consignType = '图片估计'
                switch (item.orderStatus) {
                  case 0 : item.orderStatus = '待估价'
                    break;
                  case 1 : item.orderStatus = '已估价'
                    break
                  case 10 : item.orderStatus = '待出库'
                    break
                  case 11 : item.orderStatus = '已出库'
                    break
                  case 9 : item.orderStatus = '已取消'
                    break
                  case 12 : item.orderStatus = '待收货'
                    break
                  case 13 : item.orderStatus = '已赎回'
                    break
                  case 14 : item.orderStatus = '到期不可赎回'
                    break
                  default:
                }
              }
               item.gmtCreate = this.switchTime(item.gmtCreate)
               item.gmtUpdate = this.switchTime(item.gmtUpdate)
               return item;
            });
             this.total = res.data.data.total;
          } else {
            this.$message.error(res.data.message);
          }
        })
      },
      search () {
        var data = {
          contactTel : this.pageData.phone,
          consignType : this.pageData.consignType,
          orderStatus : this.pageData.orderStatus,
          orderNo : this.pageData.name,
          orderStatus : this.pageData.orderStatus
        }
        this.getconsignIndentList(data);
      },
      getType (val) {
        switch (val) {
          case this.obj['SHANG_MEN'].key : this.state = this.obj[val].value;
            break;
          case this.obj['MEN_DIAN'].key : this.state = this.obj[val].value;
            break;
          case this.obj['KUAIDI'].key : this.state = this.obj[val].value;
              break;
          case this.obj['PREV_PIC'].key : this.state = this.obj[val].value;
            break;
          default: this.state = []
        }
      },
      details (item) {
        this.$router.push({
          name :'details',
          query : {
            id : item.orderId
          }
        })
      },
      handSize (val) {
        var data = {
          contactTel : this.pageData.phone,
          consignType : this.pageData.consignType,
          orderStatus : this.pageData.orderStatus,
          orderNo : this.pageData.name,
          current : val
        }
        this.getconsignIndentList(data);
      },
      del (item) {
        this.delMessage(()=>{
          var id = [];
          id.push(item.procedureId)
          delFlow(id).then(res=>{
            if (res.data.code == 'OK') {
              this.$message.success('删除成功');
                this.getflowList();
            } else {
              this.$message.error(res.data.message);
            }
          })
        })
      },
    }
  }
</script>

<style scoped>
  @import "../../../styles/common.css";
</style>
